<template>
	<tm-fullView>
		<template v-slot:default="{info}">
			<view :style="{minHeight:info.height+'px'}" :class="[$tm.vx.state().tmVuetify.black?'black':'grey text']">
				<tm-menubars title="识图读账" color="bg-gradient-primary-lighten" :showback="true"></tm-menubars>
				<view class="shadow-24 ">
					<tm-sheet :padding="[16,16]" :shadow="24" v-if="list.length > 0">
						<view class="text-size-s text-weight-b mb-24">
							<tm-switchList :title="item.remarks" :label="loadTypeName(item)" :actions="item_1" :icon="loadTypeIcon(item)"
								@click="viewRemarks(item,index)"
								@actionsClick="((e)=>{action(e, item,index)})" v-for="(item,index) in list" :key='index'
								:rightLabel="item.er == 1? '+'+item.value:'-'+item.value "></tm-switchList>
						</view>
					</tm-sheet>
				</view>
			</view>
		</template>
	</tm-fullView>
</template>
<script>
	import tmFullView from "@/tm-vuetify/components/tm-fullView/tm-fullView.vue"
	import tmMenubars from "@/tm-vuetify/components/tm-menubars/tm-menubars.vue"
	import tmSheet from "@/tm-vuetify/components/tm-sheet/tm-sheet.vue"
	import tmSwitchList from '@/tm-vuetify/components/tm-switchList/tm-switchList.vue'
	import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
	import tmForm from "@/tm-vuetify/components/tm-form/tm-form.vue"
	import tmPoup from "@/tm-vuetify/components/tm-poup/tm-poup.vue"
	import tmInput from "@/tm-vuetify/components/tm-input/tm-input.vue"
	import tmRadio from "@/tm-vuetify/components/tm-radio/tm-radio.vue"
	import tmGroupradio from "@/tm-vuetify/components/tm-groupradio/tm-groupradio.vue"
	import tmImages from "@/tm-vuetify/components/tm-images/tm-images.vue"
	
	export default {
		components: {
			tmFullView,
			tmMenubars,
			tmSheet,
			tmSwitchList,
			tmButton,
			tmForm,
			tmPoup,
			tmInput,
			tmRadio,
			tmGroupradio,
			tmImages
		},
		data() {
			return {
				show: false,
				list: [],
				selected: null,
				open: false,
				showremark: false,
				groupchecked: {
					c_1: true,
					c_2: false
				},
				shareurl: '',
				share: false,
				item_1: [{
						text: "删除",
						width: 140,
						color: 'red'
					}
				],
				book: {
					id: '',
					name: '',
					selected: null,
					uid: ''
				},
				id: '',
				types: []
			}
		},
		onLoad(option) {
			this.loadType()
			this.id = option.id
			this.$ajax.get('/bill/loadTemp/'+this.id).then(res => {
				this.list = res.data
			})
		},
		onShow(){
			var pages = getCurrentPages();
			var prevPage = pages[pages.length - 1];
			var brand = prevPage.brand;
			if(this.list.length > 0 && null != brand) {
				this.list.splice(brand.index,1);
			}
		},
		methods: {
			viewRemarks(val,index) {
				val.index = index
				uni.navigateTo({
					url: '/pages/index/form?value='+encodeURIComponent(JSON.stringify(val)),
				});
			},
			loadTypeName(val) {
				let t = '未知明细';
				this.types.forEach(i => {
					if (i.id == val.type) {
						t = i.text;
					}
				})
				return t;
			},
			loadTypeIcon(val) {
				let t = '';
				this.types.forEach(i => {
					if (i.id == val.type) {
						t = i.icon;;
					}
				})
				if (t == '') {
					t = 'icon-gem'
				}
				return t;
			
			},
			gogog(e) {
				if (!e) {
					this.book = {
						id: '',
						name: '',
						selected: null
					}
					this.groupchecked = {
						c_1: true,
						c_2: false
					}
				}
			},
			submit(e) {
				if (e === false) {
					uni.$tm.toast("请填写必填项")
				} else {
					this.judgeLogin(res => {
						this.book.uid = res.id
						this.$ajax.post('/book/save', this.book).then(res => {
							if (res.code == 1) {
								uni.$tm.toast("保存成功")
								this.book = {
									id: '',
									name: '',
									selected: null
								}
								this.showremark = false
								this.loadBook()
							} else {
								uni.$tm.toast('保存失败');
							}
						})
					})
				}
			},
			shiguchechange(e) {
				if ((e[0].name == '1' && e[0].checked) || (e[0].name == '0' && !e[0].checked)) {
					this.book.selected = 1;
				} else {
					this.book.selected = 0;
				}
			},
			success(e) {
				//提交成功 。
				uni.$tm.toast(e.msg)
			},
			loadType() {
				this.$ajax.get('/type/load/-1').then(res => {
					this.types = res.data
				})
			},
			loadBook() {
				this.judgeLogin(res => {
					this.$ajax.post('/book/sharelist', {
						uid: res.id
					}).then(res => {
						this.list = res.data;
					})
				})
			},
			addBook() {
				this.showremark = true;
			},
			action(e, item,index) {
				this.list.splice(index,1);
			},
			saveBook() {

			},
			openurl(e) {
				let t = this;
				console.log(e);
				uni.navigateTo({
					url: e.data.url,
					fail: e => {
						t.show = true;
					}
				})
			}
		}
	}
</script>

<style>

</style>
